/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ServicioVender.java
 *
 * Created on 21/10/2010, 01:16:40 AM
 */

package pe.edu.upla.lamerced.desk.view.hospedaje;

import javax.swing.JDesktopPane;
import javax.swing.JOptionPane;
import pe.edu.upla.lamerced.Inicial;
import pe.edu.upla.lamerced.bean.Detservicios;
import pe.edu.upla.lamerced.bean.Hospedaje;
import pe.edu.upla.lamerced.bean.Servicios;
import pe.edu.upla.lamerced.service.HospedajeService;
import pe.edu.upla.lamerced.service.ServiciosService;

/**
 *
 * @author elvis
 */
public class ServicioVender extends javax.swing.JInternalFrame {

   private HospedajeService hospedajeService;
   private ServiciosService serviciosService;
   private JDesktopPane escritorio;

   public JDesktopPane getEscritorio() {
      return escritorio;
   }
   public void setEscritorio(JDesktopPane escritorio) {
      this.escritorio = escritorio;
   }
    /** Creates new form ServicioVender */
    public ServicioVender() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        cbCliente = new javax.swing.JComboBox();
        cbServicios = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtCanidad = new javax.swing.JTextField();
        btnGrabaServicio = new javax.swing.JButton();
        btnCancelaVentaServicio = new javax.swing.JButton();

        setClosable(true);
        setTitle("Vender Servicio");

        jLabel1.setText("Habitacion");

        cbCliente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbServicios.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel2.setText("Servicio");

        jLabel3.setText("Cantidad");

        btnGrabaServicio.setText("Grabar");
        btnGrabaServicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGrabaServicioActionPerformed(evt);
            }
        });

        btnCancelaVentaServicio.setText("Cancelar");
        btnCancelaVentaServicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelaVentaServicioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(177, 177, 177)
                        .addComponent(btnCancelaVentaServicio))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(btnGrabaServicio))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel1)
                                .addComponent(jLabel2)))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtCanidad, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbCliente, 0, 169, Short.MAX_VALUE)
                            .addComponent(cbServicios, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cbCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cbServicios, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(txtCanidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(42, 42, 42)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGrabaServicio)
                    .addComponent(btnCancelaVentaServicio))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelaVentaServicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelaVentaServicioActionPerformed
       // TODO add your handling code here:
       this.dispose();
    }//GEN-LAST:event_btnCancelaVentaServicioActionPerformed

    private void btnGrabaServicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGrabaServicioActionPerformed
       try {
           Detservicios venta = new Detservicios();
           venta.setHospedaje(hospedajeService.listaHospedajesActivos().get(cbCliente.getSelectedIndex()));
           venta.setServicios(serviciosService.listaServicios().get(cbServicios.getSelectedIndex()));
           venta.setCantidad(Integer.parseInt(txtCanidad.getText()));
           serviciosService.registrarVentaServicio(venta);
           JOptionPane.showMessageDialog(this,"Servicio agregado.");
           this.dispose();
        } catch (Exception e) {
           e.printStackTrace();
           JOptionPane.showMessageDialog(this,"No se pudo grabar, disculpe la molestia.");
		}
    }//GEN-LAST:event_btnGrabaServicioActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelaVentaServicio;
    private javax.swing.JButton btnGrabaServicio;
    private javax.swing.JComboBox cbCliente;
    private javax.swing.JComboBox cbServicios;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField txtCanidad;
    // End of variables declaration//GEN-END:variables

   public void cargaInicial(){
      if(hospedajeService==null){
        hospedajeService = (HospedajeService)Inicial.getFactory().getBean("hospedajeService");
      }
       if(serviciosService==null){
        serviciosService = (ServiciosService)Inicial.getFactory().getBean("serviciosService");
      }
      cbCliente.removeAllItems();
      for(Hospedaje hos : hospedajeService.listaHospedajesActivos()){
         cbCliente.addItem(hos.getHabitacion().getNumero());
      }
      cbServicios.removeAllItems();
      for(Servicios ser : serviciosService.listaServicios()){
        cbServicios.addItem(ser.getNombre());
      }
   }
}
